package com.yunchang.springboot.scheduled.amazon.mws.report.datadispose;

import com.yunchang.springboot.models.Shop;
import com.yunchang.springboot.models.mwsreportbean.MwsInventoryStorageOverageFees;
import com.yunchang.springboot.models.mwsreportbean.MwsInventoryStorageOverageFeesDO;
import com.yunchang.springboot.scheduled.amazon.mws.report.datadispose.parent.ReportDataDisposeParent;
import com.yunchang.springboot.scheduled.amazon.mws.report.datadispose.reportinterface.IReportDataDispose;
import com.yunchang.springboot.utils.DateUtil;
import com.yunchang.springboot.utils.ToolUtil;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author czw
 */
@Component
public class InventoryStorageOverageFeesDataDispose extends ReportDataDisposeParent implements IReportDataDispose {
    /**
     * 库存仓储超量费  将获取到的数据转为实体对象数组
     *
     * @param lists
     * @param shopBrandName
     * @param area
     * @return
     * @throws Exception
     */
    @Override
    public List<Object> reportDataDispose(List<List<String>> lists, String shopBrandName, String area,String sellerId) throws Exception {
        List<Object> insertList = new ArrayList<>(lists.size());
        List<String> titleList = lists.get(0);
        Map<String, Object> titleMap = new HashMap<>(titleList.size());
        for (int i = 0; i < titleList.size(); i++) {
            titleMap.put(titleList.get(i), i);
        }
        int chargedDateIndex = Integer.valueOf(String.valueOf(titleMap.get("charged_date")));
        int storageTypeIndex = Integer.valueOf(String.valueOf(titleMap.get("storage_type")));
        int chargeRateIndex = Integer.valueOf(String.valueOf(titleMap.get("charge_rate")));
        int storageUsageVolumeIndex = Integer.valueOf(String.valueOf(titleMap.get("storage_usage_volume")));
        int storageLimitVolumeIndex = Integer.valueOf(String.valueOf(titleMap.get("storage_limit_volume")));
        int overageVolumeIndex = Integer.valueOf(String.valueOf(titleMap.get("overage_volume")));
        int volumeUnitIndex = Integer.valueOf(String.valueOf(titleMap.get("volume_unit")));
        int chargedFeeAmountIndex = Integer.valueOf(String.valueOf(titleMap.get("charged_fee_amount")));
        int currencyCodeIndex = Integer.valueOf(String.valueOf(titleMap.get("currency_code")));
        for (int i = 1; i < lists.size(); i++) {
            MwsInventoryStorageOverageFeesDO mwsInventoryStorageOverageFees = new MwsInventoryStorageOverageFeesDO();
            List<String> row = lists.get(i);
            mwsInventoryStorageOverageFees.setSellerId(sellerId);
            mwsInventoryStorageOverageFees.setArea(area);
            mwsInventoryStorageOverageFees.setChargedDate(DateUtil.ISO8601ToGMT(row.get(chargedDateIndex)));
            mwsInventoryStorageOverageFees.setStorageType(row.get(storageTypeIndex));
            mwsInventoryStorageOverageFees.setChargeRate(new BigDecimal(String.valueOf(row.get(chargeRateIndex))));
            mwsInventoryStorageOverageFees.setStorageUsageVolume(new BigDecimal(String.valueOf(row.get(storageUsageVolumeIndex))));
            mwsInventoryStorageOverageFees.setStorageLimitVolume(new BigDecimal(String.valueOf(row.get(storageLimitVolumeIndex))));
            mwsInventoryStorageOverageFees.setOverageVolume(new BigDecimal(String.valueOf(row.get(overageVolumeIndex))));
            mwsInventoryStorageOverageFees.setVolumeUnit(row.get(volumeUnitIndex));
            mwsInventoryStorageOverageFees.setChargedFeeAm(new BigDecimal(String.valueOf(row.get(chargedFeeAmountIndex))));
            mwsInventoryStorageOverageFees.setCurrencyCode(row.get(currencyCodeIndex));
            mwsInventoryStorageOverageFees.setCreateTime(DateUtil.getDate());
            mwsInventoryStorageOverageFees.setUpdateTime(DateUtil.getDate());
            mwsInventoryStorageOverageFees.setFinanceStatus(1);
            insertList.add(mwsInventoryStorageOverageFees);
        }
        return insertList;
    }
}
